﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FunctionDefinedTree.aspx.cs" Inherits="Honestysoft.Baseframework.WebUI.SystemManage.Init.FunctionDefinedTree" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../../Scripts/jquery-1.6.min.js"></script>
    <script language="javascript" type="text/javascript" src="../../Scripts/jquery.easyui.min.js"></script>
    <link href="../../Styles/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/icon.css" rel="stylesheet" type="text/css" />
    

    <script type="text/javascript">
        $(function () {
            $('#treeFunction').tree({
                checkbox: false,
                dnd: true,
                url: 'JSON/Functions.ashx?randID=' + escape(new Date()),
                method: "get",
                onClick: function (node) {
                    window.parent.window.document.getElementById("ifrmInfo").src = "FunctionDefinedInfo.aspx?ID=" + node.id;
                },
                onDrop: function (target, source, point) {
                    var parentNode = $('#treeFunction').tree('getNode', target);
                    $.ajax({
                        type: "POST",
                        url: "JSON/MoveFunction.ashx?ID=" + source.id + "&To=" + parentNode.id+"&randId="+escape(new Date()),
                        data: "",
                        success: function (msg) {
                            alert(msg);
                        }
                    });
                }
//                onContextMenu: function (e, node) {
//                    alert(node.id);
//                    
//                }
            });
        });
        function addNode(nodeId, nodeText) {
            var node = $('#treeFunction').tree('getSelected');
            $('#treeFunction').tree('append', {
                parent: (node ? node.target : null),
                data: [{
                    id:nodeId,
                    text: nodeText
                }]
            });
            $('#treeFunction').tree('expand', node.target);
        }
        function removeSelectedNode() {
            var selectedNode = $('#treeFunction').tree('getSelected');
            var node = $('#treeFunction').tree('getParent', selectedNode.target);
            $('#treeFunction').tree('remove', selectedNode.target);
            $('#treeFunction').tree('select', node.target);
            window.parent.window.document.getElementById("ifrmInfo").src = "FunctionDefinedInfo.aspx?ID=" + node.id;
        }
        function removeChildNode(arrId) {
            if (arrId == null || arrId.length == 0) {return;}
            var selectedNode = $('#treeFunction').tree('getSelected');
            var nodes = $('#treeFunction').tree('getChildren', selectedNode.target);
            if (nodes && nodes.length > 0) {
                for (var i = nodes.length - 1; i >= 0; i--) {
                    for (var j = 0; j < arrId.length; j++) {
                        if (nodes[i].id == arrId[j]) {
                            $('#treeFunction').tree('remove', nodes[i].target);
                            break;
                        }
                    }
                    
                }
            }
        }
        function reloadTree() {
            var node = $('#treeFunction').tree('getSelected');
            if (node) {
                node.text = '<span style="font-weight:bold;">' + node.text + '</span>';
                $('#treeFunction').tree('update', node);
            }
        }
        function editSelectedNode(nodeText) {
            var node = $('#treeFunction').tree('getSelected');
            if (node) {
                node.text = '<span style="font-weight:bold">' + nodeText + '</span>';
//                node.iconCls = 'icon-save';
                $('#treeFunction').tree('update', node);
            }
        }
        function editChildNode(nodeId, nodeText) {
            var selectedNode = $('#treeFunction').tree('getSelected');
            var nodes = $('#treeFunction').tree('getChildren', selectedNode.target);
            if (nodes && nodes.length > 0) {
                for (var i = nodes.length - 1; i >= 0; i--) {
                    if (nodes[i].id == nodeId) {
                        nodes[i].text = '<span style="font-weight:bold">' + nodeText + '</span>';
                        //                node.iconCls = 'icon-save';
                        $('#treeFunction').tree('update', nodes[i]);
                        break;
                    }
                }
            }
            var node = $('#tt2').tree('getSelected');
            if (node) {
                node.text = '<span style="font-weight:bold">new text</span>';
                node.iconCls = 'icon-save';
                $('#tt2').tree('update', node);
            }
        }
	</script>
</head>
<body>
    <form id="form1" runat="server">
    <ul id="treeFunction"></ul>
    </form>
</body>
</html>
